//
//  DCDriverEmptyCell.m
//  JiuyaoMotorcade
//
//  Created by 大橙子 on 2018/12/3.
//  Copyright © 2018 Tomous. All rights reserved.
//

#import "DCDriverEmptyCell.h"
static const int kBaseCellHeight = 30;
@interface DCDriverEmptyCell ()
@property (nonatomic,strong) DCImageAndTextLabel *pingjiaLabel;
@end
@implementation DCDriverEmptyCell
+(instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *CellID = @"Cell";
    DCDriverEmptyCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
    if (cell == nil) {
        cell = [[DCDriverEmptyCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = BackgroundColor;
    }
    return cell;
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUpUI];
    }
    return self;
}
-(void)setUpUI
{
    [self setUpBaseUIView];
 
    self.pingjiaLabel = [[DCImageAndTextLabel alloc]init];
    self.pingjiaLabel.imageView.image = IMAGENAME(@"bang");
    self.pingjiaLabel.textLabel.textColor = [UIColor lightGrayColor];
    [self.secondView addSubview:self.pingjiaLabel];
    
    [self.firstBtn setTitle:@"加入黑名单" forState:UIControlStateNormal];
    [self.secondBtn setTitle:@"查看评价" forState:UIControlStateNormal];
    [self.thirdBtn setTitle:@"注销" forState:UIControlStateNormal];
    
    [self.firstBtn addTarget:self action:@selector(btnDidClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.secondBtn addTarget:self action:@selector(btnDidClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.thirdBtn addTarget:self action:@selector(btnDidClick:) forControlEvents:UIControlEventTouchUpInside];
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    [self setUpLayoutSubViews];

    self.pingjiaLabel.frame = CGRectMake(self.locationLabel.x, self.locationLabel.bottom,self.locationLabel.width, kBaseCellHeight);
    
    self.thirdView.frame = CGRectMake(0, self.secondView.bottom+1, self.width, kBaseSubViewHeight);
    __weak typeof(self) weakself = self;
    [self.firstBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakself.thirdView.mas_top).offset(5);
        make.right.equalTo(weakself.thirdView.mas_right).offset(-5);
        make.width.mas_offset(80*WIDTHSCALE6);
        make.height.mas_offset(kBaseCellHeight);
    }];
    
    [self.secondBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakself.thirdView.mas_top).offset(5);
        make.right.equalTo(weakself.firstBtn.mas_left).offset(-5);
        make.width.mas_offset(80*WIDTHSCALE6);
        make.height.mas_offset(kBaseCellHeight);
    }];
    [self.thirdBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakself.thirdView.mas_top).offset(5);
        make.right.equalTo(weakself.secondBtn.mas_left).offset(-5);
        make.width.mas_offset(80*WIDTHSCALE6);
        make.height.mas_offset(kBaseCellHeight);
    }];
}
-(void)setModel:(DCDriverManagerModel *)model
{
    _model = model;
    self.nameLabel.text = model.name;
    self.stateLabel.text = model.state;
    self.plateLabel.textLabel.text = Str_IsEmpty(model.plateNum)?@"未绑定车辆":model.plateNum;
    self.phoneLabel.textLabel.text = model.tel;
    self.locationLabel.textLabel.text = model.location;
    self.pingjiaLabel.textLabel.text = model.pingjia;
}
-(void)btnDidClick:(UIButton *)button
{
    if (button.tag == 0) {
        DCLog(@"加入黑名单");
        if (_delegate && [_delegate respondsToSelector:@selector(selectedWithJionBlack:)]) {
            [_delegate selectedWithJionBlack:@""];
        }
    }else if (button.tag == 1){
        DCLog(@"查看评价");
        if (_delegate && [_delegate respondsToSelector:@selector(selectedWithChakanPingjia:)]) {
            [_delegate selectedWithChakanPingjia:self.model.name];
        }
    }else if (button.tag == 2){
        DCLog(@"注销");
        if (_delegate && [_delegate respondsToSelector:@selector(selectedWithZhuxiao:)]) {
            [_delegate selectedWithZhuxiao:@""];
        }
    }
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
